<?php

namespace plugin\webman\gateway;

use common\LogUtils;
use GatewayWorker\Lib\Gateway;

class Events
{
    public static function onWorkerStart($worker)
    {

    }

    public static function onConnect($client_id)
    {

    }

    public static function onWebSocketConnect($client_id, $data)
    {

    }

    public static function onMessage($client_id, $message)
    {
        LogUtils::info('接收到websocket消息：'.$message);
        if (!empty($message)){
            if (str_contains($message, "ping")) {
//                LogUtils::info("Message contains 'ping 心跳检测");
            }else if (str_contains($message,'bindUserId')){
                $acceptMsg = json_decode($message, true);
                if ($acceptMsg['type']=='bindUserId'){
                    Gateway::bindUid($client_id,$acceptMsg['data']['user_id']);
                }
            }else if (str_contains($message,'paySuccess')){
                $acceptMsg = json_decode($message, true);
                Gateway::sendToUid($acceptMsg['data']['user_id'],json_encode($acceptMsg));
            }
        }
    }

    public static function onClose($client_id)
    {

    }

}
